let time = 1000
import { getDict } from "@/api"


/**
 * @description 提示对话框
 */
export const Modal = function (content, confirm, cancel) {
	uni.showModal({
		title: '提示',
		content,
		success: function (res) {
			if (res.confirm) {
				if (confirm) confirm()
			} else if (res.cancel) {
				if (cancel) cancel()
			}
		}
	});
}
/**
 * @description 提示框
 */
export const Toast = function (message, icon) {
	uni.showToast({
		title: message,
		icon: icon ? icon : 'none'
	})
}
/**
 * @description 呼出拨号键盘
 */
export const MakePhoneCall = function (data) {
	uni.makePhoneCall(data)
}

/**
 * @description 获取当前页面路径
 */
export const page = function () {
	const pages = getCurrentPages()
	// 某些特殊情况下(比如页面进行redirectTo时的一些时机)，pages可能为空数组
	return `/${pages[pages.length - 1]?.route ?? ''}`
}
/**
 * @description 获取字典数据
 */
export const getDicts = function (dicts) {
	let data = {}
	let option = {}
	let promoses = dicts.map((item) => {
		data[item] = {}
		return getDict(item)
	});
	return Promise.all(promoses).then(res => {
		res.forEach(item => {
			option[item.data[0].dictType] = item.data.map(item => {
				return {
					value: item.dictValue,
					text: item.dictLabel
				}
			})
			item.data.forEach(child => {
				data[child.dictType][child.dictValue] = child.dictLabel
			})
		})
		return {
			data,
			option
		}
	})

}